package com.sdhs.paas.rc.service;

import java.util.List;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.sdhs.paas.sdk.base.common.BaseDao;
import com.sdhs.paas.sdk.base.common.BasePage;
import com.github.pagehelper.Page;
import com.sdhs.paas.sdk.core.PaasBaseException;
import com.sdhs.paas.sdk.core.mybatis.EnablePaasMybatis;
import com.sdhs.paas.rc.bean.DocCategoryBean;
import com.sdhs.paas.rc.repository.DocCategoryMapper;
import com.sdhs.paas.sdk.base.common.entity.PaginationEntity;
import com.github.pagehelper.PageHelper;

/**
* 描述：DocCategoryService 服务接口
* @author kangjichang
* @date 2018-12-07
*/

@EnablePaasMybatis
@MapperScan("com.sdhs.paas.rc.repository")
@Service
public class DocCategoryService extends BaseDao<DocCategoryBean, DocCategoryMapper, Integer>{
		@Override
		public String getMapperNamespace() {
			return DocCategoryMapper.class.getName();
		}
		
		@Autowired
		private DocCategoryMapper docCategoryMapper;
		
		public PaginationEntity<DocCategoryBean> getPageDocCategoryList(BasePage pageRequest, DocCategoryBean docCategoryBean) {
			Page<DocCategoryBean> pageTotal = PageHelper.startPage(pageRequest.getPage(), pageRequest.getPageSize(),true, false);
			List<DocCategoryBean> list = docCategoryMapper.getList(docCategoryBean);
			PaginationEntity<DocCategoryBean> paginationEntity = new PaginationEntity<DocCategoryBean>(list,
	                (int) pageTotal.getTotal());
			return paginationEntity;
		}
		
		@Transactional(rollbackFor = Exception.class)
		public boolean saveDocCategory(DocCategoryBean docCategoryBean) {
			try {
				//ucAppBean.setCtime(System.currentTimeMillis());
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docCategoryMapper.insertDocCategory(docCategoryBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		@Transactional(rollbackFor = Exception.class)
		public boolean updateDocCategory(DocCategoryBean docCategoryBean) {
			try {
				//ucAppBean.setUtime(System.currentTimeMillis());
				int count = docCategoryMapper.updateDocCategory(docCategoryBean);
				return count == 1;
			} catch (Exception e) {
				throw new PaasBaseException(e, "500", "数据库插入异常！");
			}
		}
	
		public DocCategoryBean getDocCategoryDetail(String id) {
			return docCategoryMapper.getDocCategoryDetail(id);
		}
		
		public boolean deleteDocCategory(DocCategoryBean docCategoryBean){
			return docCategoryMapper.deleteDocCategory(docCategoryBean)>0;
		}
      
}